import React from "react";
import axios from "axios";
axios.defaults.timeout = 50000;

let fundId = window.location.href;
fundId = fundId.toString().split('=');
if (fundId.length == 2){
    fundId = fundId[1] + '';
}
let zeronum = 0
for(var i=0;i<fundId.length;i++){
    if(fundId[i] == 0){
        zeronum = zeronum+1;
    }else {
        break;
    }
}
console.log(zeronum)
fundId = fundId.slice(zeronum,)
console.log(fundId)

export default class Fund_price extends React.Component{
    constructor(props) {
        super(props);
        this.state={
            fund_data:[],
        };
        var FUNDID=window.location.href.split('=')[1];
        axios.get(global.routes.database+'/getFunds', {
            params: {
                fundID: FUNDID,
            }
        }).then((res)=>{



            switch (res.data.Data.FCODE.toString().length) {
                case 1:
                    res.data.Data.FCODE = '00000'+res.data.Data.FCODE.toString();
                    break;
                case 2:
                    res.data.Data.FCODE = '0000'+res.data.Data.FCODE.toString();
                    break;
                case 3:
                    res.data.Data.FCODE = '000'+res.data.Data.FCODE.toString();
                    break;
                case 4:
                    res.data.Data.FCODE = '00'+res.data.Data.FCODE.toString();
                    break;
                case 5:
                    res.data.Data.FCODE = '0'+res.data.Data.FCODE.toString();
                    break;
                case 6:
                    res.data.Data.FCODE = res.data.Data.FCODE.toString();
                    break;
            }
            switch (res.data.Data.DWJZ.toString().length) {
                case 1:
                    res.data.Data.DWJZ = res.data.Data.DWJZ.toString() + '.0000';
                    break;
                case 2:
                    res.data.Data.DWJZ = res.data.Data.DWJZ.toString() + '0000';
                    break;
                case 3:
                    res.data.Data.DWJZ = res.data.Data.DWJZ.toString() + '000';
                    break;
                case 4:
                    res.data.Data.DWJZ = res.data.Data.DWJZ.toString() + '00';
                    break;
                case 5:
                    res.data.Data.DWJZ = res.data.Data.DWJZ.toString()  + '0';
                    break;
                case 6:
                    res.data.Data.DWJZ = res.data.Data.DWJZ.toString();
                    break;
            }
            this.setState({
                fund_data:res.data.Data,
            });
        })
        ;
    };
    render() {
        return (
            <div style={{width:'100%%',height:'80px',marginTop:'50px',borderTop:'0.5px solid lightgray'}}>
                <div style={{width:'auto',margin:'10px auto 10px 40px',padding:'0',float:'left'}}>
                    <p style={{fontSize:'14px',margin:'0',padding:'0'}}>日涨跌幅</p>
                    <p style={{fontSize:'24px',fontWeight:'bold',margin:'0',padding:'0'}}>{this.state.fund_data.RZDF}%</p>
                </div>
                <div style={{width:'auto',margin:'10px 40px 10px auto',padding:'0',float:'right'}}>
                    <p style={{fontSize:'14px',margin:'0',padding:'0'}}>单位净值</p>
                    <p style={{color:'orangered',fontSize:'24px',fontWeight:'bold',margin:'0',padding:'0'}}>{this.state.fund_data.DWJZ}</p>
                </div>
            </div>
        );
    }
}